<?php

class XmlFactory {
	
	public static function ct($s, $o) {
		if($o == 'o'){
			return '&lt;'.$s.'&gt;';
		}else if ($o == 'c'){
			return '&lt;/'.$s.'&gt;';
		}else {
			return '&lt;'.$s.' '.$o.'"&gt;';
		}
		/*if($o == 'o'){
			return '<'.$s.'>';
		}else if ($o == 'c'){
			return '</'.$s.'>';
		}else {
			return '<'.$s.' '.$o.'">';
		}*/
	}    
	
	public static function buildSearchXml($eventId) {
		$outputXml = XmlFactory::ct('event', 'o');
		
		$row = DataBaseController::row("SELECT * FROM ".Constans::$EVENT." WHERE event_id='$eventId'");
		
		//event
		$outputXml .= XmlFactory::ct('name', 'o').$row['name'].XmlFactory::ct('name', 'c');
		$outputXml .= XmlFactory::ct('description', 'o').$row['description'].XmlFactory::ct('description', 'c');
		$outputXml .= XmlFactory::ct('value', 'o').$row['value'].XmlFactory::ct('value', 'c');
		
		//category
		$result = DataBaseController::execute("SELECT * FROM ".Constans::$CATEGORYMAPPING." WHERE event_id='$eventId'");
		$outputXml .= XmlFactory::ct('categores', 'o');	
		while($data=mysql_fetch_assoc($result)){
			$categoryId = $data['category_id'];
			$categoryResult = DataBaseController::execute("SELECT * FROM ".Constans::$CATEGORY." WHERE category_id='$categoryId'");
			while($categoryData=mysql_fetch_assoc($categoryResult)){
				$outputXml .= XmlFactory::ct('category', 'o').$categoryData['name'].XmlFactory::ct('category', 'c');
			}
		}	
		$outputXml .= XmlFactory::ct('categores', 'c');		
		
		//tag
		$result = DataBaseController::execute("SELECT * FROM ".Constans::$TAGMAPPING." WHERE event_id='$eventId'");
		$outputXml .= XmlFactory::ct('tags', 'o');	
		while($data=mysql_fetch_assoc($result)){
			$tagId = $data['tag_id'];
			$tagResult = DataBaseController::execute("SELECT * FROM ".Constans::$TAG." WHERE tag_id='$tagId'");
			while($tagData=mysql_fetch_assoc($tagResult)){
				$outputXml .= XmlFactory::ct('tag', 'o').$tagData['name'].XmlFactory::ct('tag', 'c');
			}
		}	
		$outputXml .= XmlFactory::ct('tags', 'c');
		
		//place
		$eventlocationId = $row['eventlocation_id'];
		$result = DataBaseController::row("SELECT * FROM ".Constans::$EVENTLOCATION." WHERE eventlocation_id='$eventlocationId'");
		$outputXml .= XmlFactory::ct('eventlocation', 'o');
		
		$outputXml .= XmlFactory::ct('eventlocation_id', 'o').$result['eventlocation_id'].XmlFactory::ct('eventlocation_id', 'c');
		$outputXml .= XmlFactory::ct('name', 'o').$result['name'].XmlFactory::ct('name', 'c');
		$outputXml .= XmlFactory::ct('adress', 'o').$result['adress'].XmlFactory::ct('adress', 'c');
		$outputXml .= XmlFactory::ct('city', 'o').$result['city'].XmlFactory::ct('city', 'c');
		$outputXml .= XmlFactory::ct('location', 'o').$result['location'].XmlFactory::ct('location', 'c');
		$outputXml .= XmlFactory::ct('x', 'o').$result['x'].XmlFactory::ct('x', 'c');
		$outputXml .= XmlFactory::ct('y', 'o').$result['y'].XmlFactory::ct('y', 'c');
		$outputXml .= XmlFactory::ct('description', 'o').$result['description'].XmlFactory::ct('description', 'c');
		$outputXml .= XmlFactory::ct('marker', 'o').$result['marker'].XmlFactory::ct('marker', 'c');
		
		$outputXml .= XmlFactory::ct('eventlocation', 'c');	
		
		$outputXml .= XmlFactory::ct('event', 'c');
		
		return $outputXml;
	}  
    
}

?>